home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 155 < prev    next >
Encoding:
Text File  |  1996-08-05  |  5.4 KB  |  119 lines

  1. Path: newton.uncg.edu!news
  2. From: "Monica M. Chew" <mmchew@hamlet.uncg.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: This is an unreasonable request
  5. Date: 2 Jan 1996 14:47:55 GMT
  6. Organization: University of North Carolina at Greensboro
  7. Message-ID: <4cbgir$mks@newton.uncg.edu>
  8. NNTP-Posting-Host: shannon.uncg.edu
  9. Mime-Version: 1.0
  10. Content-Type: multipart/mixed;
  11.     boundary="-------------------------------21923304281857"
  12. X-Mailer: Mozilla 1.1N (X11; I; SunOS 5.4 sun4m)
  13. X-URL: file:/afs/uncg.edu/user/m/mmchew/help_me.txt
  14.  
  15. This is a multi-part message in MIME format.
  16.  
  17. ---------------------------------21923304281857
  18. Content-Transfer-Encoding: 7bit
  19. Content-Type: text/plain; charset=us-ascii
  20.  
  21. -- 
  22. mmchew@hamlet.uncg.edu
  23.  
  24. ---------------------------------21923304281857
  25. Content-Transfer-Encoding: 7bit
  26. Content-Type: text/plain
  27.  
  28. Hello to all the gurus out there,
  29.  
  30. I'm trying to convert Sparc assembly to DEC Alpha assembly with little
  31. success.  I am hoping that someone loves this kind of stuff and will
  32. be able to code the following in DEC Alpha with no problem:
  33.  
  34.  
  35. #ifdef sparc  
  36. /**************************************************************************************\
  37. *************************** SPARC Assembley Language Macros ****************************
  38. \**************************************************************************************/
  39.  
  40. /*
  41.  * SAVE_CONTEXT is invoked from within ContextSwitchto or ContextSwitchback. *
  42.  * Both of these routines are treated as non-leaf procedures by the SPARC C  *
  43.  * compiler.  Consequently, the only registers that need to be saved are the *
  44.  * frame pointer (%i6) and the return address (%i7).                         *
  45.  *                                                                           *
  46.  * 0x03 is the ST_FLUSH_WINDOWS software trap.  It causes all of the         *
  47.  * registers sets cached in register windows to be flushed to memory (each   *
  48.  * register set being stored in the appropriate frame on the user stack) and *
  49.  * the WIM register is adjusted so that when the process to which control is *
  50.  * being switched executes a return from whatever procedure it is currently  *
  51.  * in, a trap occurs to cause the previous register set to be read from      *
  52.  * memory.                                                                   *
  53.  *                                                                           */
  54.  
  55. #define SAVE_CONTEXT(addr)                       \
  56.         YS__CxtPtr = addr;                       \
  57.         asm("sethi %hi(YS__CxtPtr),%o0");       \
  58.         asm("ld   [%o0+%lo(YS__CxtPtr)],%o0");  \
  59.         asm("std  %i6,[%o0+8]");                 \
  60.         asm("ta   0x03");
  61.  
  62. /*                                                                          *
  63.  * RESTORE_CONTEXT restores the frame pointer and stack pointer that were   *
  64.  * saved in the new process context at the last time control was            *
  65.  * transferred from the new context.  At the completion of RESTORE_CONTEXT, *
  66.  * execution within ContextSwitchto or ContextSwitchback continues.  When   *
  67.  * either of these routines terminate, it is the return address that has    *
  68.  * just been restored by RESTORE_CONTEXT that determines that control       *
  69.  * returns to the instruction in the new process just after its last call   *
  70.  * to ContextSwitchto or ContextSwitchback.                                 *
  71.  *                                                                          */
  72.  
  73. #define RESTORE_CONTEXT(addr)                    \
  74.         YS__CxtPtr = addr;                       \
  75.         asm("sethi %hi(YS__CxtPtr),%o0");       \
  76.         asm("ld    [%o0+%lo(YS__CxtPtr)],%o0"); \
  77.         asm("ldd   [%o0+8],%i6");
  78.  
  79. /*                                                                          *
  80.  * INITIAL_CONTEXT is necessary because the first time control is           *
  81.  * transferred to a new context, there is no saved return address to be     *
  82.  * used.  We cannot simply put the entry point for ContextTerminate as the  *
  83.  * return address and use RESTORE_CONTEXT because control would then never  *
  84.  * be transferred to the entry point for the new context.  Instead, we must *
  85.  * put the entry point for ContextTerminate in %o7 to be used as the return *
  86.  * address when the process running in the new context terminates.  We must *
  87.  * also set up the frame pointer and stack pointer for the new context (see *
  88.  * InitContext() in machdep.c).  Finally, we use the entry point of the     *
  89.  * new process (which was stored in the context descriptor) to jump         *
  90.  * to the start of the new context root procedure.                          *
  91.  *                                                                          */
  92.  
  93. #define INITIAL_CONTEXT(addr)                    \
  94.         YS__CxtPtr = addr;                       \
  95.         asm("sethi %hi(YS__CxtPtr),%o0");       \
  96.         asm("ld    [%o0+%lo(YS__CxtPtr)],%o0"); \
  97.         asm("ld    [%o0+12],%o7");                \
  98.         asm("ld    [%o0+12],%i7");                \
  99.         asm("ld    [%o0+16],%o1");               \
  100.         asm("ld    [%o0+8],%i6");                \
  101.         asm("add   %i6,104,%i6");                \
  102.         asm("ld    [%o0+8],%o6");                \
  103.         asm("jmpl  %o1,%o2");                    \
  104.         asm("nop");
  105.  
  106. #endif /*************************** End of SPARC code *********************************/
  107.  
  108. Many thanks for your time.  Please send replies and suggestions to 
  109.  
  110. mmchew@hamlet.uncg.edu
  111.  
  112. Thanks,
  113. Monica
  114.  
  115.  
  116.  
  117.  
  118. ---------------------------------21923304281857--
  119.